<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 86137
  Date: 2021/8/2
  Time: 19:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户列表信息</title>

    <style>
        a{text-decoration: none;}
        table{border: yellow 1px; width: 700px; text-align: center; line-height: 28px; margin: 0 auto;}
            th{background-color: antiquewhite; color: blue}

    </style>


</head>
<body>
        <table border="solid" cellspacing="0">


            <tr>

                <th><input type="checkbox" onclick="checkAll(this)"></th>

                <th>序号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>现居地</th>
                <th>QQ</th>
                <th>邮箱</th>
                <th>操作</th>
            </tr>

            <%--<c:forEach var="u" items="${users}" varStatus="s">--%>

            <c:forEach items="${pb.list}" var="u" varStatus="s">

            <tr>
                <td><input type="checkbox" name="id"></td>

                <td>${s.count}</td>
                <td>${u.name}</td>
                <td>${u.gender}</td>
                <td>${u.age}</td>
                <td>${u.address}</td>
                <td>${u.qq}</td>
                <td>${u.email}</td>
                <td><a href="${pageContext.request.contextPath}/userServlet?method=findById&upid=${u.id}">修改</a>&nbsp;
                    <a href="javascript:void(0)" onclick="deleteUser(${u.id}) ">删除</a></td>

            </tr>

            </c:forEach>

            <tr>
                <td style="border: none" colspan="8"><a href="${pageContext.request.contextPath}/add.jsp">添加用户</a>&nbsp;&nbsp;<a href="${pageContext.request.contextPath}/index.jsp">返回主页</a></td>
            </tr>

            <tr>
                <td colspan="9">

                                        <%--分页--%>

                    <a href="javascript:goPage(1)">首页</a>
                    <a href="javascript:goPage(${pb.prePage})" >上一页</a>
                    <c:forEach begin="${pb.navigateFirstPage}" end="${pb.navigateLastPage}" var="i" >
                        <a href="javascript:goPage(${i})">${i}</a>
                    </c:forEach>
                    <a href="javascript:goPage(${pb.pageNum+1})">下一页</a>
                    <a href="javascript:goPage(${pb.pages})">尾页</a>
                    总共${pb.pages}页.共${pb.total}条

                    <form id="pageForm" action="${pageContext.request.contextPath}/userServlet?method=findAll" method="post">
                        <input type="hidden" name="pageNum" id="pageNum" >
                    </form>
                    <script>
                        function goPage(page) {
                            document.getElementById("pageNum").value=page;
                            document.getElementById("pageForm").submit()
                        }
                    </script>



                </td>
            </tr>

        </table>























</body>

<script>

    /*删除提示框*/
    function deleteUser(id) {
        if (confirm("亲，您确认要删除么？")){
            location.href="${pageContext.request.contextPath}/userServlet?method=delete&delid="+id;
        }
    }

    /*全选和全不选*/
    function checkAll(checkboxEle) {
       let ids  =document.getElementsByName("id");
       /*遍历数组*/
        for (let i=0; i<ids.length; i++ ){
            ids[i].checked=checkboxEle.checked;
        }

    }












</script>


</html>
